Skip to content
This repository has been archived by the owner on Jan 20, 2020. It is now read-only.

Simplify OrderbookSync constructor signature #177

Merged
merged 3 commits into from
Dec 25, 2017

Conversation

rmm5t
Copy link
Contributor

@rmm5t rmm5t commented Dec 25, 2017

This is a direct follow-up to #151 (comment)

  • Adds a checkAuth() utility function to ensure an auth object contains key, secret, and passphrase
  • Simplifies OrderbookSync constructor to take auth object instead of a full AuthenticatedClient instance

This is still backwards compatible with the old constructor signature, because AuthenticatedClient has the same key, secret, and passphrase properties.

/cc @fb55

@rmm5t rmm5t force-pushed the simplify-orderbook-sync-signature branch from 481193e to 11cf861 Compare December 25, 2017 04:44
@@ -147,18 +141,17 @@ suite('OrderbookSync', () => {
});
});

test('emits an error event on error (with AuthenticatedClient)', done => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could one of these still use an authenticated client, to ensure we don't break backwards compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I don't think we should have tests for that, because we're moving forward with the API. The benefit of previously changing the AuthenticatedClient properties and the backwards compatibility that comes with it is just a nice and elegant side effect . Backwards compatibility guarantees can be good sometimes, but they can also hold things back long-term.

Nonetheless, with that off my chest, I'm happy to add an extra test with AuthenticatedClient if would make you feel more comfortable. I'm just not sure this is the correct place to test that AuthenticatedClient quacks like an auth payload object of { key, secret, passphrase }.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra test using an instance of AuthenticatedClient was just added via 09be1e8.


this._queues = {}; // []
this._sequences = {}; // -1
this._public_clients = {};
this.books = {};

if (this.auth.secret) {
this._authenticatedClient = new AuthenticatedClient(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this default to auth if it already is an instance of AuthenticatedClient?

Copy link
Contributor Author

@rmm5t rmm5t Dec 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote no...for the same reasons as above. We should not be making side-effect assumptions about the passed object, aside from the fact that it quacks like a { key, secret, passphrase } object. Otherwise, the project opens itself to a world of forwards compatibility issues and limitations down the road.

i.e. "Optimizations" like this only yield future maintenance problems. There's almost zero overhead to having an extra AuthenticatedClient instance.

e.g. If we did reuse a passed-in AuthenticationClient, the apiURI argument passed to the OrderbookSync constructor would then be ignored, and you'd end up with unintended consequences of talking to the wrong endpoint.

@fb55 fb55 merged commit 9802f7f into coinbase:master Dec 25, 2017
@fb55
Copy link
Contributor

fb55 commented Dec 25, 2017

Awesome, thanks a lot!

@rmm5t rmm5t deleted the simplify-orderbook-sync-signature branch December 25, 2017 22:31
@rmm5t rmm5t mentioned this pull request Dec 28, 2017
@blair
Copy link
Contributor

blair commented Feb 28, 2018

It appears to me that this commit goes in the opposite direction of dependency injection: https://en.wikipedia.org/wiki/Dependency_injection . Normally, one passes in all the objects that an object needs in its constructor and constructors don't construct other objects. It's ok to have to build an AuthenticatedClient and then pass it to a OrderbookSync even if the code is a little longer.

This principle also makes it easier to pass in mock objects if one wanted to. Having a constructor construct objects itself removes this possibility.

If you're concerned about the two URIs being out of sync, then just drop the URI argument.

Unless there's something I'm missing, I suggest reverting this commit and only taking a PublicClient instance (which should have AuthenticatedClient as a sublcass, but that doesn't look like it was fixed until a week ago in 60f8014 ). So wait until gdax-tt upgrades to the latest gdax.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants